// ###############
// FILE : HitAction.java
// WRITER : Ido Adler, idoa03, 039809181
// WRITER : Gal Bartfeld, gbartf99, 20144546
// EXERCISE : oop herobots 2009
// DESCRIPTION:
// TODO: add description
// ###############
package warbots.entities.actions;


import java.awt.Point;

import warbots.entities.units.Unit;
import warbots.gameplay.Map;


/**
 * TODO: add description
 * 
 * @author Ido Adler.
 * @author Gal Bartfeld.
 */
public class HitAction extends Action
{
    /**
     * TODO: description
     * 
     * @param parent
     * @param name
     * @param distance
     */
    public HitAction(final Unit parent, final String name)
    {
        super(parent, name);
    }
    
    /**
     * @see warbots.entities.actions.Action#execute(warbots.gameplay.Map,
     *      java.awt.Point)
     */
    @Override
    public boolean execute(final Map world, final Point target)
    {
        if (target.distance(_parent.getPosition()) <= 1)
        {
            Unit enemy = world._board[target.x][target.y].getUnit();
            if ((enemy != null) && (enemy != _parent))
            {
                enemy.getHit(this);
                System.out
                    .println(_parent.getName() + ":" + getName() + "->" + enemy.getName());
                return true;
            }
        }
        return false;
    }
}
